package com.shujia.java.day15.demo2;

import java.io.FileInputStream;
/**
 * @Description: Demo3
 * @Author: 王火火
 * @Date: 2019/8/17 14:36
 *
 * 3个read 返回值都是int  不是数组的长度 (获取数据的数量)
 *   1.read()
 *   2.read(byte[] b)
 *   3.read(byte[] b,int off,int len)
 */
public class Demo3 {
    public static void main(String[] args) throws Exception {
        // 第一步 创建流对象 文件不存就报错
        FileInputStream fis = new FileInputStream("test.txt");
        //2.read(byte[] b)
//        byte[] bytes = new byte[10];
//        int i;
//        while ((i = fis.read(bytes)) != -1) {
//            // System.out.print((char)i);
//            System.out.print(new String(bytes,0,i));
//        }

        //3.read(byte[] b,int off,int len)
        byte[] bytes = new byte[10];
//        //两个 获取一部分
//        System.out.println(fis.read(bytes,0,5));
//        System.out.print(new String(bytes,0,10));
//
//        System.out.println(fis.read(bytes,0,5));
//        System.out.print(new String(bytes,0,10));

        //没啥用
        int i ;
        while ((i =fis.read(bytes,0,5))!=-1){
            System.out.print(new String(bytes,0,10));
        }
        //关闭流
        fis.close();
    }
}
